import WxRequest from '../libs/wx-request/lib/core/WxRequest';
import Promise from '../libs/es6-promise';
import config from '../config';
class Api{
  constructor(){
      this.request = new WxRequest({
          baseURL : config.host
      });
      this.request.interceptors.use({
        // 统一全局拦截
        responseError(responseError) {
          wx.showToast({
            title : '接口错误',
            icon : 'none'
          })
          return Promise.reject(responseError)
        }
      });
  }
 //get请求
  //首页
  home(){
    var url = '/api/index/index';
    return this.request.getRequest(url, {
      data: {
      }
    }).then(function (obj) {
      return obj.data.data;
    });
  }
  //咨询列表
  getConsultation(data) {
    var url = '/api/index/newslist';
    return this.request.getRequest(url, {
      data
    }).then(function (obj) {
      return obj.data.data;
    });
  }
  //咨询列表详情
  getConsultationDetails(data) {
    var url = '/api/index/newsinfo';
    return this.request.getRequest(url, {
      data
    }).then(function (obj) {
      return obj.data.data;
    });
  }
  ///课程列表
  getCourse() {
    var url = '/api/index/kclist';
    return this.request.getRequest(url, {
      data: {
      }
    }).then(function (obj) {
      return obj.data.data;
    });
  }
  //课程详情/api/index/kcinfo
  getCoursedetails(data) {
    var url = '/api/index/kcinfo';
    return this.request.getRequest(url, {
      data
    }).then(function (obj) {
      return obj.data;
    });
  }
  //课程支付接口
  payCourse(data) {
    var url = '/api/index/usecoin';
    return this.request.getRequest(url, {
      data
    }).then(function (obj) {
      return obj.data;
    });
  }
  //我的课程
  getMyCourse(data) {
    var url = '/api/index/mykc';
    return this.request.getRequest(url, {
      data
    }).then(function (obj) {
      return obj.data;
    });
  }
  //关于我们
  aboutUS() {
    var url = '/api/index/about';
    return this.request.getRequest(url, {
      data: {
      }
    }).then(function (obj) {
      return obj.data;
    });
  }
  //我的资料
  getmyinfo(data) {
    var url = '/api/index/getUserInfo';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //我的资料
  updatemyinfo(data) {
    var url = '/api/index/updateUser';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //我的金币数据
  getmycoin(data) {
    var url = '/api/index/mycoin';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //我的金币支出列表
  getmyPayList(data) {
    var url = '/api/index/paylist';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //金币付款接口
  gopay(data) {
    var url = '/api/index/setPay';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //支付成功回调
  gopayCallBack(data) {
    var url = '/api/index/addcoin';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //获取openid
  getOpenid(data) {
    var url = '/api/index/getOpenid';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data
    });
  }
  //解密
  decode(data) {
    var url = '/api/index/decode';
    return this.request.postRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data;
    });
  }
  //微信登入创建临时用户
  wxlogin(data) {
    var url = '/api/index/setUser';
    return this.request.postRequest(url, { data }).then(function (obj) {
      return obj.data;
    });
  }
  //获取用户信息
  getUserInfo(data) {
    var url = '/api/index/getUserInfo';
    return this.request.getRequest(url, {
      data: data
    }).then(function (obj) {
      return obj.data;
    });
  }
}
export default Api;
